<?php
error_reporting(0);

$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);

$filePath = realpath(__DIR__ . '/./jstools/data.json');
$fileContent = file_get_contents($filePath);
$fileLength = strlen($fileContent);
echo $fileLength;

$client->set(array(
    "socket_buffer_size"=>2*1024*1024,
    'package_eof' => "\r\n\r\n",
));

$client->on("connect", function ($cli) {
    echo "connect\n";
    echo $cli->setting["package_max_length"]."\n";
    global $fileContent;
    $cli->send($fileContent."\r\n\r\n");
});
$client->on("receive", function ($cli, $data) {
    echo "received: {$data}\n";
});
$client->on("error", function ($cli) {
    echo "connect failed\n";
});
$client->on("close", function ($cli) {
    echo "connection close\n";
});
$client->connect("127.0.0.1", 8091, 0.5);
